Give user's compiler flags precedence over default ones
authorSandrine Bailleux <[email protected]>
Mon, 11 Apr 2016 12:01:17 +0000 (13:01 +0100)
committerSandrine Bailleux <[email protected]>
Thu, 14 Apr 2016 15:16:37 +0000 (16:16 +0100)
The user can provide additional CFLAGS to use when building TF.
However, these custom CFLAGS are currently prepended to the
standard CFLAGS that are hardcoded in the TF build system. This
is an issue because when providing conflicting compiler flags
(e.g. different optimisations levels like -O1 and -O0), the last
one on the command line usually takes precedence. This means that
the user flags get overriden.

To address this problem, this patch separates the TF CFLAGS from
the user CFLAGS. The former are now stored in the TF_CFLAGS make
variable, whereas the CFLAGS make variable is untouched and reserved
for the user. The order of the 2 sets of flags is enforced when
invoking the compiler.

Fixes ARM-Software/tf-issues#350

Change-Id: Ib189f44555b885f1dffbec6015092f381600e560

Makefile
make_helpers/build_macros.mk
make_helpers/windows.mk

index c5ec6d1c655335e43b3c8aef10058faee7cf9b1a..b1560a2ba881d0962729a366bbbd97ec2c989e62 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -136,7 +136,7 @@ export Q
 $(eval $(call add_define,DEBUG))
 ifneq (${DEBUG}, 0)
         BUILD_TYPE     :=      debug
-        CFLAGS         +=      -g
+        TF_CFLAGS      +=      -g
         ASFLAGS                +=      -g -Wa,--gdwarf-2
         # Use LOG_LEVEL_INFO by default for debug builds
         LOG_LEVEL      :=      40
@@ -179,12 +179,12 @@ ASFLAGS                   +=      -nostdinc -ffreestanding -Wa,--fatal-warnings   \
                                -Werror -Wmissing-include-dirs                  \
                                -mgeneral-regs-only -D__ASSEMBLY__              \
                                ${DEFINES} ${INCLUDES}
-CFLAGS                 +=      -nostdinc -ffreestanding -Wall                  \
+TF_CFLAGS              +=      -nostdinc -ffreestanding -Wall                  \
                                -Werror -Wmissing-include-dirs                  \
                                -mgeneral-regs-only -mstrict-align              \
                                -std=c99 -c -Os                                 \
                                ${DEFINES} ${INCLUDES}
-CFLAGS                 +=      -ffunction-sections -fdata-sections
+TF_CFLAGS              +=      -ffunction-sections -fdata-sections
 
 LDFLAGS                        +=      --fatal-warnings -O1
 LDFLAGS                        +=      --gc-sections
@@ -331,7 +331,7 @@ endif
 
 # Check if -pedantic option should be used
 ifeq (${DISABLE_PEDANTIC},0)
-        CFLAGS         +=      -pedantic
+        TF_CFLAGS      +=      -pedantic
 endif
 
 # Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be
@@ -487,7 +487,7 @@ msg_start:
 
 # Check if deprecated declarations should be treated as error or not.
 ifeq (${ERROR_DEPRECATED},0)
-    CFLAGS             +=      -Wno-error=deprecated-declarations
+    TF_CFLAGS          +=      -Wno-error=deprecated-declarations
 endif
 
 # Expand build macros for the different images
index 5171ff00641181b3d007194f1cd59e755e63b5b7..c963b7afdeee9c3a8bac2a07d45e1d2585c50867 100644 (file)
@@ -208,11 +208,11 @@ $(eval IMAGE := IMAGE_BL$(call uppercase,$(3)))
 
 $(OBJ): $(2)
        @echo "  CC      $$<"
-       $$(Q)$$(CC) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@
+       $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@
 
 $(PREREQUISITES): $(2) | bl$(3)_dirs
        @echo "  DEPS    $$@"
-       $$(Q)$$(CC) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$<
+       $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$<
 
 ifdef IS_ANYTHING_TO_BUILD
 -include $(PREREQUISITES)
@@ -351,7 +351,7 @@ ifdef MAKE_BUILD_STRINGS
 else
        @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \
               const char version_string[] = "${VERSION_STRING}";' | \
-               $$(CC) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o
+               $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o
 endif
        $$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \
                                        $(BUILD_DIR)/build_message.o $(OBJS)
index 8ac82460f03ddec15b624c89bae3619bf5c34e11..fe5e8c1fecd5609d97234c6bcec6a1b260dbf57a 100644 (file)
@@ -104,6 +104,6 @@ BUILT_TIME_DATE_STRING = const char build_message[] = "Built : "${BUILD_MESSAGE_
 VERSION_STRING_MESSAGE = const char version_string[] = "${VERSION_STRING}";
 define MAKE_BUILD_STRINGS
        @echo $$(BUILT_TIME_DATE_STRING) $$(VERSION_STRING_MESSAGE) | \
-               $$(CC) $$(CFLAGS) -x c - -o $1
+               $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -x c - -o $1
 endef